setGlobalDuration(20)

example = 1

if example == 1:
    env = genAdsr()
    a = genWaveform([1,0,.3])
    b = genWaveform([1,0,.3,0,.2,0,.143])
    c = genWaveform([1,0,.3,0,.2,0,.143,0,.111,0,.1])
    d = genWaveform([1,0,.3,0,.2,0,.143,0,.111,0,.1,0,.09,0,.07])

    linsegr('line', 0, 2, 0, 10, 1, 5, 1)
    wave = tableMorphing([a,b,c,d], indexVar='line', length=8192)

    waveform(pitch=100, envelope=env, table=wave)

elif example == 2:
    env = genAdsr()
    a = genWaveform([1,0,.3])
    b = genWaveform([1,0,.3,0,.2,0,.143])
    c = genWaveform([1,0,.3,0,.2,0,.143,0,.111,0,.1])
    d = genWaveform([1,0,.3,0,.2,0,.143,0,.111,0,.1,0,.09,0,.07])

    linsegr('line', 0, 2, 0, 10, 1, 5, 1)
    wave = tableMorphing([a,b,c,d], indexVar='line', length=8192)

    randomi(bus=[1,2,3,4,5], mini=0.99, maxi=1.01, rate=[1.2,1.5,2.3,3.1,.7])
    pitchs = [random.randint(490,510)*.2 for i in range(20)]
    waveform(pitch=pitchs, amplitude=.07, envelope=env, pitchVar=[1,2,3,4,5], table=wave)

elif example == 3:
    env = genAdsr()
    a = genWaveform([1,0,.3,0,0,.4,0,.2,0,0.1])
    b = genWaveform([1,0,.3,0,.2,0,.143,0,0,.2,0,.1])
    c = genWaveform([1,.4,0,.3,0,.2,0,.143,0,0,.111,0,.1])
    d = genWaveform([1,0,0,.3,0,0,.2,0,.3,.143,0,.111,0,.1,0,.09,0,.07])

    randomi('rnd', rate=.5)
    wave = tableMorphing([a,b,c,d], indexVar='rnd', length=8192)

    randomi(bus=[1,2,3,4,5], mini=0.99, maxi=1.01, rate=[1.2,1.5,2.3,3.1,.7])
    pitchs = [random.randint(490,510)*.2 for i in range(20)]
    waveform(pitch=pitchs, amplitude=.07, envelope=env, pitchVar=[1,2,3,4,5], table=wave)

startCsound()